import request from "@/utils/request";

export const file = {
  upload: (data) => {
    return request({
      url: "file/upload",
      method: "post",
      data: data,
    });
  },
  downLoadFile: (id) => {
    return request({
      method: "get",
      responseType: "blob",
      url: "/charge/downLoad/" + id,
    }).then((res) => {
      const blob = new Blob([res.data], {
        type: `application/.${file.type.toLowerCase()}`,
      });
      const link = document.createElement("a");
      link.href = window.URL.createObjectURL(blob);
      link.download = file.name;
      link.click();
      link.remove();
    });
  },
  del: (id) => {
    return request({
      url: "file/deleteById",
      method: "get",
      params: {
        id,
      },
    });
  },
  getFile: (url) => {
    return request({
      url: "/file/loadFile",
      method: "get",
      responseType: "blob",
      params: {
        url,
      },
    });
  },
};
